'''
Created on 2010-4-17

@author: Zizon
'''
from google.appengine.ext import webapp
from time import time
from urllib import urlencode , quote
from hmac import HMAC
from hashlib import sha1
from random import getrandbits
     
class OauthProcessor(webapp.RequestHandler):
    oauth = {
              "oauth_consumer_key" : "ABf8MU9zwivnRBLGbaRyw",
              "oauth_signature_method" :"",
              "oauth_signature" : "",
              "oauth_timestamp":"",
              "oauth_nonce":"",
              "oauth_version":"1.0"
            }
       
    def generateUrl(self):
        oauth = {
              "oauth_consumer_key" : "ABf8MU9zwivnRBLGbaRyw",
              "oauth_signature_method" :"HMAC-SHA1",
              "oauth_timestamp":int(time()),
              "oauth_nonce":getrandbits(64),
              "oauth_version":"1.0"
            }
        urlencode(oauth)
        
    def get(self, *args):
        pass
    
    def post(self, *args):
        pass

def test():
    oauth_consumer_secret = "6TtNMUYWxhe4Fk9qUMKG4YTl92UXP7afiBN4cV8mQ"
    oauth = {
              "oauth_consumer_key" : "ABf8MU9zwivnRBLGbaRyw",
              "oauth_signature_method" :"HMAC-SHA1",
              "oauth_timestamp":int(time()),
              "oauth_nonce":getrandbits(64),
              "oauth_version":"1.0"
            }
    message = "&".join(["GET" , quote("https://api.twitter.com/oauth/request_token", ""), urlencode(oauth)])
    print message
    oauth["oauth_signature"] = HMAC(oauth_consumer_secret , message , sha1).digest().encode('base64')[:-1]
    print "%s?%s" % ("https://api.twitter.com/oauth/request_token" , urlencode(oauth))
      
